﻿using System;
using System.Collections.Generic;
using System.Text;

using Shared;
using JoltEnvironment.Sql;

namespace Shared
{
    public class DatabaseManager
    {
        #region Fields

        /// <summary>
        /// JoltEnvironment database manager.
        /// </summary>
        private SqlDatabaseManager Manager;

        #endregion

        #region Constructor

        /// <summary>
        /// Constructs a new database manager.
        /// </summary>
        public DatabaseManager()
        {
            Configuration SqlConfig = new Configuration("Configuration\\MySQL.conf");

            SqlDatabaseServer Server = new SqlDatabaseServer(
                SqlConfig.Get("MySQL.Host", "localhost"),
                ushort.Parse(SqlConfig.Get("MySQL.Port", "3306")),
                SqlConfig.Get("MySQL.Username", "root"),
                SqlConfig.Get("MySQL.Password", "root"));

            SqlDatabase Database = new SqlDatabase(
                SqlConfig.Get("MySQL.Database", "dail_db"),
                uint.Parse(SqlConfig.Get("MySQL.PoolMin", "0")),
                uint.Parse(SqlConfig.Get("MySQL.PoolMax", "100")));

            this.Manager = new SqlDatabaseManager(Database, Server);
        }

        #endregion

        #region Methods

        /// <summary>
        /// Gets an available client from the Jolt MySQL manager.
        /// </summary>
        /// <returns>MySQL Client</returns>
        public SqlDatabaseClient GetClient()
        {
            return this.Manager.GetClient();
        }

        #endregion
    }
}